""" DigitalICS: mobile data collection tool to complete surveys with integrated multimedia

    Copyright (C) 2009. Yael Schwartzman  

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>
    
    Contact information: Yael Schwartzman -  yaelsf@gmail.com
    """
from api.form import Form

class Controller:
    """ Controls navigation within form"""
    
    def __init__(self,form,prompt_id = 0,view = "Shell"):
        self.form = form
        self.prompt_id = prompt_id
        
    def set_prompt_id(self,prompt_id):
        self.prompt_id = prompt_id
    
    def get_prompt_id(self):
        return self.prompt_id 
            
    def complete_form(self,prompt_id = 0):
        self.prompt_id = prompt_id
        prompt = self.form.get_prompt(index = self.prompt_id)
        return prompt
    
    def get_next_prompt(self):
        self.prompt_id+= 1
        if self.prompt_id < self.form.size():
            prompt = self.form.get_prompt(index = self.prompt_id)
            if self.form.prompt_is_relevant(prompt):
                return prompt                
            else:
                return self.get_next_prompt()
        else:
            return False
                
    def get_prev_prompt(self):
        self.prompt_id-= 1
        if self.prompt_id == -1:
            return False
        else:
            prompt = self.form.get_prompt(index = self.prompt_id)
            if self.form.prompt_is_relevant(prompt):
                return prompt
            else:
                return self.get_prev_prompt()


    